package com.rp.demo.service.impl;

import cn.hutool.core.util.IdUtil;
import cn.hutool.json.JSONUtil;
import com.rp.demo.commons.MessageHelper;
import com.rp.demo.commons.ResponseCode;
import com.rp.demo.commons.ServerResponse;
import com.rp.demo.config.RabbitConfig;
import com.rp.demo.config.RabbitLaQuConfig;
import com.rp.demo.dto.Mail;
import com.rp.demo.dto.MessageEntity;
import com.rp.demo.entity.MsgLog;
import com.rp.demo.mapper.MsgLogMapper;
import com.rp.demo.service.TestService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.connection.CorrelationData;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 发送消息业务层
 */
@Service
@Slf4j
public class LaquServiceImpl {

    @Autowired
    private RabbitTemplate rabbitTemplate;

    public ServerResponse sendLaqu(MessageEntity entity) {

        CorrelationData correlationData = new CorrelationData(entity.getMsgId());
        rabbitTemplate.convertAndSend(
                RabbitLaQuConfig.LAQU_EXCHANGE_NAME,
                RabbitLaQuConfig.LAQU_ROUTING_KEY_NAME,
                MessageHelper.objToMsg(entity),
                correlationData);// 发送消息

        return ServerResponse.success("发送拉取信息成功");
    }

}